package com.booth.manage.model;

import java.util.Date;

import com.booth.base.model.Users;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
/***
 * 	摊位经营者控制器
 * @author Admin
 *
 */
public class BussOperator extends Model<BussOperator> {
	
	private static final long serialVersionUID = 1L;
	public static BussOperator dao=new BussOperator();
	/***
	 * 根据过滤条件获取数据并分页
	 * @param cardNo 
	 * @param page：当前页
	 * @param pageSize：每页条数
	 * @param name：内容名称
	 * @param beginDate：开始时间
	 * @param endDate：结束时间
	 * @return 返回满足过滤条件的数据结合，否则放回null
	 */
	public Page<BussOperator> findPage(int page,int pageSize,String name,String accountName,String phone, String cardNo){
		
		String whereString = " WHERE 1=1 and t.is_delete = 0 ";
		if(name != null && !name.equals(""))
		{
			whereString=whereString+" AND t.name like('%"+name+"%')";
		}
		if(accountName != null && !accountName.equals(""))
		{
			whereString=whereString+" AND t.account_name like('%"+accountName+"%')";
		}
		if(phone != null && !phone.equals(""))
		{
			whereString=whereString+" AND t.phone like('%"+phone+"%')";
		}
		if(cardNo != null && !cardNo.equals(""))
		{
			whereString=whereString+" AND t.card_no like('%"+cardNo+"%')";
		}
		return dao.paginate(page, pageSize, "SELECT t.*  ", " FROM buss_opetator t "+ whereString +" order by t.create_time desc");
		
	}
	public boolean deleteById(Integer selectId,Users curUser) {
		Record record = new Record().set("is_delete", 1).set("updator_id", curUser.getUserId()).set("updator_name", curUser.getUserName())
		.set("update_time", new Date()).set("id", selectId);
		
		return Db.update("buss_opetator", "id", record);
	}
}
